package com.v5ba.server.service.impl;

import com.v5ba.server.entity.db1.User;
import com.v5ba.server.entity.db2.SysLog;
import com.v5ba.server.repository.db1.UserRepository;
import com.v5ba.server.repository.db2.SysLogRepository;
import com.v5ba.server.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author yiren
 * @date 2018/6/17
 */
@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private SysLogRepository sysLogRepository;

    @Override
    @Transactional
    public void exec() {

        System.out.println("====执行开始");
        User user = new User();
        user.setName("张三");
        user.setPhone("18611912657");
        userRepository.save(user);

        SysLog log = new SysLog();
        log.setType("系统日志");
        log.setContent("系统日志");
        sysLogRepository.save(log);
        //执行错误信息，检查是否回滚
        int i = 1 / 0;
        System.out.println("====执行结束");

    }
}
